package kg.aibek.projecteuler.p51;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class Problem65 {
	private static int LEVEL = 100 - 1;

	public BigInteger solve() {
		List<Integer> list = new ArrayList<Integer>();

		list.add(2);
		for (int i = 1; list.size() < 100; i++) {
			list.add(1);
			list.add(i * 2);
			list.add(1);
		}

		BigInteger num = BigInteger.ONE;
		BigInteger den = BigInteger.valueOf(list.get(LEVEL));
		BigInteger a = null;
		for (int i = LEVEL; i > 0; i--) {
			a = BigInteger.valueOf(list.get(i - 1));
			BigInteger dd = den;
			den = den.multiply(a).add(num);
			num = dd;
		}

		System.out.println(num);
		System.out.println(den);
		System.out.println(a);
		return den;
	}

	private static int digitSums(BigInteger bi) {
		int sum = 0;
		for (char ch : bi.toString().toCharArray()) {
			sum += Integer.parseInt(ch + "");
		}

		return sum;
	}

	public static void main(String[] args) {
		Problem65 p = new Problem65();

		System.out.println(digitSums(p.solve()));
	}
}
